/**
 * Create in 2012-7-27.
 */
package kit4j.tests.jdk.swing.dnd.component;

import java.awt.Container;
import java.awt.datatransfer.Transferable;

import javax.swing.JComponent;
import javax.swing.TransferHandler;

import kit4j.view.cs.swing.dnd.LocalObjectRefTransferable;

/**
 * 
 * @author MiniKnife
 *
 */
public class JButtonTransferHandler extends TransferHandler {

	private static final long serialVersionUID = -5146646551035148667L;

	@Override
	public int getSourceActions(JComponent source) {
		return MOVE | COPY | LINK;
	}

	@Override
	protected Transferable createTransferable(JComponent source) {
		return new LocalObjectRefTransferable(source);
	}

	@Override
	protected void exportDone(JComponent source, Transferable data, int action) {
	}

	@Override
	public boolean canImport(TransferSupport support) {
		Container container = support.getComponent().getParent();

		if (container != null && container instanceof JComponent) {
			JComponent con = (JComponent) container;

			return con.getTransferHandler().canImport(support);
		} else {
			return false;
		}
	}

	@Override
	public boolean importData(TransferSupport support) {
		Container container = support.getComponent().getParent();

		if (container != null && container instanceof JComponent) {
			JComponent con = (JComponent) container;

			return con.getTransferHandler().importData(support);
		} else {
			return false;
		}
	}
}
